import { Body, Controller, Get, Param, Post, Req, UseGuards } from "@nestjs/common";
import { PactService } from "../service/pact.service";
import { Request } from "express";
import { jsonBaseResponse } from "../utils/response/response";
import { UserEntity } from "../entity/user.entity";
import { AuthGuard } from "@nestjs/passport";
import { SignPactDto } from "../dto/signPact.dto";
import { SignStudentPactDto } from "../dto/signStudentPact.dto";
import { PactDetailDto } from "../dto/pact.dto";

@Controller("/api/pact")
@UseGuards(AuthGuard("jwt"))
export class PactController {
  constructor(
    private readonly pactService: PactService
  ) {
  }

  @Get("/getPactList")
  async getPactList(@Req() req: Request) {
    return jsonBaseResponse(await this.pactService.getPactList(req.user["user"] as UserEntity));
  }


  @Get("/getPactPreviewPic/:id")
  async getPactPreviewPic(@Param() param: any) {
    return jsonBaseResponse(await this.pactService.getPactPreviewPic(param.id));
  }

  //签署合同
  @Post("/signPact")
  async signPact(@Body() body: SignPactDto, @Req() req: Request) {
    return jsonBaseResponse(await this.pactService.signPact(req.user["user"] as UserEntity, body));
  }

  //签署学员合同
  @Post("/signStudentPact")
  async signStudentPact(@Body() body: SignStudentPactDto, @Req() req: Request) {
    return jsonBaseResponse(await this.pactService.signStudentPact(req.user["user"] as UserEntity, body));
  }

  @Post("/getPactDetail")
  async getPactDetail(@Body() body: PactDetailDto, @Req() req: Request) {
    return jsonBaseResponse(await this.pactService.getPactDetail(body, req.user["user"] as UserEntity));
  }

  //获取用户已签署的合同列表
  @Get("/getUserSignedPactList")
  async getUserSignedPactList(@Req() req: Request) {
    return jsonBaseResponse(await this.pactService.getUserSigningContracts(req.user["user"] as UserEntity));
  }
}
